﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using Autodesk.Revit.DB;
using YArchitech.LIB;

namespace FetchDataCompare
{
	public class XMLOperator
	{
		public XMLOperator()
		{
			this.XmlDoc = new XmlDocument();
			string filename = Product.DataLocation + "\\CategoryList.xml";
			this.XmlDoc.Load(filename);
			this.m_assembly = Assembly.GetAssembly(typeof(Wall));
		}

		public ICollection<BuiltInCategory> GetNeedCheckCategory()
		{
			ICollection<BuiltInCategory> collection = new List<BuiltInCategory>();
			XmlNode documentElement = this.XmlDoc.DocumentElement;
			foreach (object obj in documentElement.ChildNodes)
			{
				XmlNode xmlNode = obj as XmlNode;
				BuiltInCategory item = (BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), xmlNode.Name);
				collection.Add(item);
			}
			return collection;
		}

		public IList<Type> GetNeedCheckClass(ref IList<Type> class2DList)
		{
			IList<Type> list = new List<Type>();
			XmlNode documentElement = this.XmlDoc.DocumentElement;
			foreach (object obj in documentElement.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (!(xmlNode.Name == "OST_Lines"))
				{
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj2;
						if (xmlNode2.InnerText == "3D")
						{
							list.Add(this.GetType(xmlNode2.Name));
						}
						else
						{
							class2DList.Add(this.GetType(xmlNode2.Name));
						}
					}
				}
			}
			return list;
		}

		public List<string> GetNeedCheckAttribute(string categoryName)
		{
			List<string> list = new List<string>();
			XmlNode documentElement = this.XmlDoc.DocumentElement;
			foreach (object obj in documentElement[categoryName].Attributes)
			{
				XmlAttribute xmlAttribute = obj as XmlAttribute;
				list.Add(xmlAttribute.Name);
			}
			return list;
		}

		private Type GetType(string className)
		{
			IEnumerable<Type> exportedTypes = this.m_assembly.ExportedTypes;
			foreach (Type type in exportedTypes)
			{
				if (type.Name == className)
				{
					return type;
				}
			}
			return null;
		}

		public string GetGeoObjectStructType(string xpath)
		{
			XmlNode xmlNode = this.XmlDoc.SelectSingleNode(xpath);
			return xmlNode.Attributes[0].Name;
		}

		private Assembly m_assembly = Assembly.GetAssembly(typeof(Wall));

		private XmlDocument XmlDoc;

		public static XmlNode XmlDocument;
	}
}
